package org.jeecg.modules.flow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.flow.entity.ActHiActInstance;
import org.jeecg.modules.flow.mapper.ActHiActInstanceMapper;
import org.jeecg.modules.flow.query.HistoryActivityQuery;
import org.jeecg.modules.flow.service.IActHiActInstanceService;
import org.jeecg.modules.flow.vo.HistoryActivityInstanceVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description: hi_actinst
 * @Author: zzq
 * @Date: 2021-12-29
 * @Version: V1.0
 */
@Service
public class ActHiActInstanceServiceImpl extends ServiceImpl<ActHiActInstanceMapper, ActHiActInstance> implements IActHiActInstanceService {

    @Resource
    private ActHiActInstanceMapper actHiActInstanceMapper;

    @Override
    public Page<HistoryActivityInstanceVo> queryHistoricActivityInstance(HistoryActivityQuery query, Integer pageNo, Integer pageSize) {
        QueryWrapper<ActHiActInstance> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getProcessInstanceId()), "RES.PROC_INST_ID_", query.getProcessInstanceId())
                .eq(StringUtils.isNotBlank(query.getBusinessKey()), "AHP.BUSINESS_KEY_", query.getBusinessKey())
                .orderByAsc("RES.START_TIME_");


        return actHiActInstanceMapper.queryHistoricActivityInstance(queryWrapper, query.getBusinessKey(), new Page<>(pageNo, pageSize));
    }
}
